<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     Pagizer
 * @subpackage  backoffice
 */

class m_backoffice_actions_FormSubmitAction extends f_core_Action
{
	public function execute()
	{
		$parameters = $this->getRequest()->getParameterValues("form");
		
		$tempDocService = m_backoffice_services_TempDocService::getInstance();
		
		if($tempDocService->hasTemporary($parameters['id']))
		{
			$document = $tempDocService->getTemporaryDocument($parameters['id']);
		}
		else
		{
			$document = f_document_Provider::getInstance()->getByUniqueId($parameters['id']);			
		}
		
		unset($parameters['submit'], $parameters['id']);
		
		foreach($parameters as $var => $value)
		{
			$methodName = "set".ucfirst($var);
			$document->$methodName(stripslashes($value));
		}
		
		$tempDocService->saveTemporaryDocument($document);
		
		unset($_POST);
	}	
	
	public function validate()
	{
		return true;
	}
}